﻿using System;
using System.IO;
using System.Xml;

namespace IDI.Studio.Core.Util
{
    public class XmlUtil
    {
        public static XmlDocument GetXmlDocument(string fileName)
        {
            string startPath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] { '\\' });
            string filePath = string.Format("{0}\\{1}", startPath, fileName);

            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException(string.Format("Can not found the xml document at {0}", filePath));
            }

            var document = new XmlDocument();

            using (var reader = new XmlTextReader(filePath))
            {
                document.Load(reader);
            }

            return document;
        }
    }
}
